//
//  SINAMsgDetaileViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/29.
//  Copyright © 2017年  androidlongs. All rights reserved.
//  消息详情

#import "SINAMsgDetaileViewController.h"
#import "SINACalendarUtils.h"
#import "SINACircularBeadUtils.h"

@interface SINAMsgDetaileViewController ()
@property (weak, nonatomic) IBOutlet UIView *msgDetailView;

@end

@implementation SINAMsgDetaileViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    self.navigationItem.title=@"消息通知";
    // Do any additional setup after loading the view from its nib.
}

-(void) initView{
    self.view.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
    self.msgDetailView.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, mainW, mainH)];
    
    scrollView.backgroundColor=[UIColor colorWithHexString:@"#eeeeee"];
    NSString *msgTitle = self.model.title;
    
    if (msgTitle==nil||[msgTitle isEqualToString:@""]) {
        NSString *msgType=self.model.messagetypename;
        if (msgType==nil) {
            msgType = self.model.msgTypeName;
        }
        msgTitle = msgType;
    }
    
    UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, mainW, 68)];
    [scrollView addSubview:headerView];
    //headerView.backgroundColor = [UIColor blueColor];
    
    UIImageView *titleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(12, CGRectGetHeight(headerView.frame)-48, 40, 40)];
    [headerView addSubview:titleImageView];
    
    if (self.model.createuseravatar!=nil) {
         [titleImageView sd_setImageWithURL:[NSURL URLWithString:self.model.createuseravatar] placeholderImage:[UIImage imageNamed:@"默认头像"]];
    } else {
        NSDictionary *infoPlist = [[NSBundle mainBundle] infoDictionary];
        
        NSString *icon = [[infoPlist valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
        
        UIImage* image = [UIImage imageNamed:icon];
        titleImageView.image = image;
    }
    
   
    
    [SINACircularBeadUtils makeCircularView:titleImageView];
    
    if (self.model.createusername==nil) {
        self.model.createusername=self.model.messagetypename;
    }
    
    UILabel *createMsgLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(titleImageView.frame)+12, CGRectGetHeight(headerView.frame)/2-4, mainW/2, 21)];
    createMsgLabel.text=self.model.createusername;
    [createMsgLabel setFont:[UIFont systemFontOfSize:16]];
    createMsgLabel.textColor=[UIColor colorWithHexString:@"#212121"];
    //createMsgLabel.backgroundColor=[UIColor yellowColor];
    [headerView addSubview:createMsgLabel];
    
    
    NSString *msgCreateTime =self.model.createtime;
    if (msgCreateTime==nil) {
        msgCreateTime = self.model.time;
    }
    
    UILabel *timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(createMsgLabel.frame), CGRectGetHeight(headerView.frame)/2, mainW-CGRectGetMaxX(createMsgLabel.frame)-12, 21)];
    //yyyy-MM-dd HH:mm
    timeLabel.text = [NSString stringWithFormat:@"%@",[SINACalendarUtils getDateStringWithTimeStr:msgCreateTime andFormat:@"MM/dd HH:mm"]];
    timeLabel.textAlignment=NSTextAlignmentRight;
    [timeLabel setFont:[UIFont systemFontOfSize:14]];
    timeLabel.textColor=[UIColor colorWithHexString:@"#878787"];
    
    [headerView addSubview:timeLabel];
    
    
    UIView *diviView =[[UIView alloc]initWithFrame:CGRectMake(12, CGRectGetMaxY(headerView.frame), mainW-12*2, 1)];
    diviView.backgroundColor=[UIColor colorWithHexString:@"#dddddd"];
    [scrollView addSubview:diviView];
    
    
    
    
    
    UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(headerView.frame)+4, mainW-30, 44)];
    titleLabel.text=msgTitle;
    [titleLabel setFont:[UIFont systemFontOfSize:14]];
    titleLabel.textColor=[UIColor colorWithHexString:@"#212121"];
    
    [scrollView addSubview:titleLabel];
    
    
    NSString *Content=self.model.content;
    if (Content==nil) {
        Content=self.model.msgContent;
    }
    
    UILabel *label = [[UILabel alloc] init];
    
    CGRect rect  = [Content boundingRectWithSize:CGSizeMake(mainW-24, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15]} context:nil];
    CGSize s = rect.size;
    //求文本的大小
    label.font =[UIFont systemFontOfSize:15];
    label.frame =CGRectMake(15, CGRectGetMaxY(titleLabel.frame), s.width, s.height);
    label.text =Content;
    
    label.lineBreakMode = NSLineBreakByWordWrapping;
    
    label.numberOfLines = 0;
    label.textColor=[UIColor colorWithHexString:@"#676767"];
    label.backgroundColor =[UIColor clearColor];
   
    scrollView.contentSize = label.frame.size;
   
    [scrollView addSubview:label];
    
    
    [self.msgDetailView addSubview:scrollView];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
